package com.jielihaofeng.nettyadvance.protocol;

import lombok.Data;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Johnnie Wind
 * @description 消息
 * @date 2021/11/16 16:51
 */
@Data
public abstract class Message implements Serializable {

    private int sequenceId;
    private int messageType;

    public abstract int getMessageType();

    public static final int LoginRequestMessage = 0;
    public static final int LoginResponseMessage = 1;
    public static final int RequestMessage = 2;
    public static final int ResponseMessage = 3;
    public static final int ChatRequestMessage = 4;
    public static final int ChatResponseMessage = 5;
    public static final int GroupCreateRequestMessage = 6;
    public static final int GroupCreateResponseMessage = 7;
    public static final int GroupJoinRequestMessage = 8;
    public static final int GroupJoinResponseMessage = 9;
    public static final int GroupQuitRequestMessage = 10;
    public static final int GroupQuitResponseMessage = 11;
    public static final int GroupChatRequestMessage = 12;
    public static final int GroupChatResponseMessage = 13;
    public static final int PingMessage = 14;
    public static final int PongMessage = 15;

    // 请求类型byte值
    public static final int RPC_MESSAGE_TYPE_REQUEST = 101;
    // 响应类型byte值
    public static final int RPC_MESSAGE_TYPE_RESPONSE = 102;

    private static final Map<Integer,Class<? extends Message>> messageClasses = new HashMap<>();
    static {
        messageClasses.put(LoginRequestMessage,LoginRequestMessage.class);
    }

    public static Class<? extends Message> getMessageClass(int messageType){
        return messageClasses.get(messageType);
    }
}
